/*
day436 
2020.11.6 
*/

#include<iostream>
#include<vector>
using namespace std;

struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};

class Solution {
public:
    ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
		ListNode *head=new ListNode(0),*rear=head;
		ListNode *p1=l1,*p2=l2;
		while(p1&&p2)
		{
			if(p1->val<p2->val)
			{
				rear->next=p1;
				p1=p1->next;
			}
			else
			{
				rear->next=p2;
				p2=p2->next;
			}
			
			rear=rear->next;
			rear->next=nullptr;
		}
		
		if(p1)
		{
			rear->next=p1;
		}
		if(p2)
		{
			rear->next=p2;
		}
		
		l1=head->next;
		delete(head);
		return l1;
		
    }
};

int main()
{
	return 0;
 } 
